package 滑动窗口;

/**
 * @author: yangwk37982
 * @date: 2022/10/10 10:21
 */
public class 连续乘积小于指定集 {
    public static void main(String[] args) {
        int[] continueArr = new int[]{10, 5, 2, 6};
        int target = 100;
        System.out.println(continueMul(continueArr, target));
    }

    public static int continueMul(int[] arr, int target) {
        int result = 0;
        int mul = 1;
        int left = 0;
        for (int right = 0; right < arr.length; right++) {
            int num = arr[right];
            mul = mul * num;
            while (mul >= target && left <= right) {
                mul = mul / arr[left++];
            }
            result += right - left + 1;
        }
        return result;
    }
}
